from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-09 14:07:09.341608
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 09, Nov, 2022
Time: 14:07:18
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.9119
Nobs: 835.000 HQIC: -51.2261
Log likelihood: 10895.1 FPE: 4.65551e-23
AIC: -51.4214 Det(Omega_mle): 4.18250e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297972 0.050915 5.852 0.000
L1.Burgenland 0.109094 0.034899 3.126 0.002
L1.Kärnten -0.106540 0.018590 -5.731 0.000
L1.Niederösterreich 0.210456 0.072992 2.883 0.004
L1.Oberösterreich 0.100611 0.069458 1.449 0.147
L1.Salzburg 0.251270 0.037018 6.788 0.000
L1.Steiermark 0.035615 0.048573 0.733 0.463
L1.Tirol 0.107277 0.039351 2.726 0.006
L1.Vorarlberg -0.059103 0.033914 -1.743 0.081
L1.Wien 0.057691 0.062304 0.926 0.354
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067876 0.105117 0.646 0.518
L1.Burgenland -0.031279 0.072050 -0.434 0.664
L1.Kärnten 0.047266 0.038380 1.232 0.218
L1.Niederösterreich -0.173293 0.150694 -1.150 0.250
L1.Oberösterreich 0.378520 0.143399 2.640 0.008
L1.Salzburg 0.288804 0.076425 3.779 0.000
L1.Steiermark 0.106160 0.100280 1.059 0.290
L1.Tirol 0.316434 0.081242 3.895 0.000
L1.Vorarlberg 0.023638 0.070016 0.338 0.736
L1.Wien -0.017596 0.128629 -0.137 0.891
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195702 0.026309 7.439 0.000
L1.Burgenland 0.091880 0.018033 5.095 0.000
L1.Kärnten -0.009072 0.009606 -0.944 0.345
L1.Niederösterreich 0.266943 0.037717 7.078 0.000
L1.Oberösterreich 0.116384 0.035891 3.243 0.001
L1.Salzburg 0.051770 0.019128 2.706 0.007
L1.Steiermark 0.016183 0.025099 0.645 0.519
L1.Tirol 0.097750 0.020334 4.807 0.000
L1.Vorarlberg 0.056959 0.017524 3.250 0.001
L1.Wien 0.116634 0.032194 3.623 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105512 0.026961 3.914 0.000
L1.Burgenland 0.046610 0.018480 2.522 0.012
L1.Kärnten -0.017211 0.009844 -1.748 0.080
L1.Niederösterreich 0.195904 0.038651 5.069 0.000
L1.Oberösterreich 0.282599 0.036780 7.684 0.000
L1.Salzburg 0.120138 0.019602 6.129 0.000
L1.Steiermark 0.102086 0.025720 3.969 0.000
L1.Tirol 0.122018 0.020837 5.856 0.000
L1.Vorarlberg 0.069554 0.017958 3.873 0.000
L1.Wien -0.027915 0.032991 -0.846 0.397
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128175 0.048949 2.619 0.009
L1.Burgenland -0.049628 0.033551 -1.479 0.139
L1.Kärnten -0.039889 0.017872 -2.232 0.026
L1.Niederösterreich 0.166130 0.070173 2.367 0.018
L1.Oberösterreich 0.139284 0.066776 2.086 0.037
L1.Salzburg 0.284813 0.035589 8.003 0.000
L1.Steiermark 0.033430 0.046697 0.716 0.474
L1.Tirol 0.163668 0.037832 4.326 0.000
L1.Vorarlberg 0.104704 0.032604 3.211 0.001
L1.Wien 0.071075 0.059898 1.187 0.235
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061048 0.038725 1.576 0.115
L1.Burgenland 0.041745 0.026543 1.573 0.116
L1.Kärnten 0.049633 0.014139 3.510 0.000
L1.Niederösterreich 0.227492 0.055515 4.098 0.000
L1.Oberösterreich 0.272574 0.052828 5.160 0.000
L1.Salzburg 0.058310 0.028155 2.071 0.038
L1.Steiermark -0.008631 0.036943 -0.234 0.815
L1.Tirol 0.155686 0.029929 5.202 0.000
L1.Vorarlberg 0.068746 0.025794 2.665 0.008
L1.Wien 0.074132 0.047386 1.564 0.118
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181460 0.046358 3.914 0.000
L1.Burgenland -0.004429 0.031775 -0.139 0.889
L1.Kärnten -0.061322 0.016926 -3.623 0.000
L1.Niederösterreich -0.085547 0.066459 -1.287 0.198
L1.Oberösterreich 0.191985 0.063241 3.036 0.002
L1.Salzburg 0.058837 0.033705 1.746 0.081
L1.Steiermark 0.226263 0.044225 5.116 0.000
L1.Tirol 0.495174 0.035829 13.820 0.000
L1.Vorarlberg 0.048764 0.030878 1.579 0.114
L1.Wien -0.049187 0.056727 -0.867 0.386
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.157503 0.052873 2.979 0.003
L1.Burgenland -0.009988 0.036241 -0.276 0.783
L1.Kärnten 0.064614 0.019305 3.347 0.001
L1.Niederösterreich 0.202663 0.075798 2.674 0.008
L1.Oberösterreich -0.066460 0.072129 -0.921 0.357
L1.Salzburg 0.222715 0.038441 5.794 0.000
L1.Steiermark 0.113070 0.050440 2.242 0.025
L1.Tirol 0.083377 0.040864 2.040 0.041
L1.Vorarlberg 0.122693 0.035218 3.484 0.000
L1.Wien 0.111482 0.064700 1.723 0.085
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.353594 0.030943 11.427 0.000
L1.Burgenland 0.008010 0.021210 0.378 0.706
L1.Kärnten -0.024614 0.011298 -2.179 0.029
L1.Niederösterreich 0.227555 0.044360 5.130 0.000
L1.Oberösterreich 0.163118 0.042213 3.864 0.000
L1.Salzburg 0.052269 0.022497 2.323 0.020
L1.Steiermark -0.016716 0.029520 -0.566 0.571
L1.Tirol 0.114577 0.023915 4.791 0.000
L1.Vorarlberg 0.072488 0.020611 3.517 0.000
L1.Wien 0.050833 0.037865 1.342 0.179
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043046 0.158134 0.191193 0.164981 0.129653 0.122352 0.068914 0.229497
Kärnten 0.043046 1.000000 0.000825 0.131689 0.044535 0.098883 0.428009 -0.051088 0.102467
Niederösterreich 0.158134 0.000825 1.000000 0.343354 0.164691 0.309624 0.124842 0.190652 0.337383
Oberösterreich 0.191193 0.131689 0.343354 1.000000 0.235276 0.338993 0.176950 0.178975 0.270728
Salzburg 0.164981 0.044535 0.164691 0.235276 1.000000 0.152797 0.143176 0.152321 0.140112
Steiermark 0.129653 0.098883 0.309624 0.338993 0.152797 1.000000 0.162266 0.147862 0.090265
Tirol 0.122352 0.428009 0.124842 0.176950 0.143176 0.162266 1.000000 0.120893 0.161783
Vorarlberg 0.068914 -0.051088 0.190652 0.178975 0.152321 0.147862 0.120893 1.000000 0.015023
Wien 0.229497 0.102467 0.337383 0.270728 0.140112 0.090265 0.161783 0.015023 1.000000